﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCell.Constants;
using WCell.Constants.World;
using WCell.Core.DBC;
using WCell.Util.Graphics;

namespace WCell.RealmServer.Global
{
    public class MapDifficultyConverter : DBCRecordConverter<MapDifficultyInfo>
    {
        public override MapDifficultyInfo ConvertTo(byte[] rawData, ref int id)
        {
            id = GetInt32(rawData, 0);

            var info = new MapDifficultyInfo();

            info.Id = (uint)id;
            info.MapId = (MapId) GetUInt32(rawData, 1);
            info.Difficulty = (DungeonDifficulty)GetUInt32(rawData, 2);
            info.AreaTriggerString = GetString(rawData, 3);
            info.TextFlags = GetUInt32(rawData, 19);
            info.ResetTime = GetUInt32(rawData, 20);

            return info;
        }
    }

	public class MapConverter : DBCRecordConverter<RegionInfo>
	{
		public override RegionInfo ConvertTo(byte[] rawData, ref int id)
		{
			id = GetInt32(rawData, 0);

			var rgn = new RegionInfo();

			rgn.Id = (MapId) GetUInt32(rawData, 0);
			//rgn.InternalName = GetString(rawData, 1);
			rgn.Type = (MapType)GetUInt32(rawData, 2);
			rgn.HasTwoSides = GetUInt32(rawData, 3) != 0;
			rgn.Name = GetString(rawData, 4);
			//rgn.MinLevel = GetInt32(rawData, 21);
			//rgn.MaxLevel = GetInt32(rawData, 22);
			//rgn.MaxPlayerCount = GetInt32(rawData, 23);

			rgn.AreaTableId = GetUInt32(rawData, 21);
			rgn.LoadScreen = GetUInt32(rawData, 56);

			rgn.HordeText = GetString(rawData, 22);
			rgn.AllianceText = GetString(rawData, 39);

			rgn.ParentMapId = (MapId) GetInt32(rawData, 58);

			// TODO: Determine Z level
			rgn.RepopRegionId = rgn.ParentMapId;
			rgn.RepopPosition = new Vector3(GetFloat(rawData, 59), GetFloat(rawData, 60), 500);

            rgn.MaxPlayerCount = GetInt32(rawData, 64);

            //rgn.HeroicResetTime = GetUInt32(rawData, 113);
            //rgn.RaidResetTime = GetUInt32(rawData, 112);

			return rgn;
		}
	}
}
